package com.huai.demo_test1.singletionsecond.lazy;/** * 懒汉式单例模式 * 延迟加载 * 解决懒汉式在多线程情况下的线程安全问题 */public class LazySingletonSync {    private static LazySingletonSync lazySingleton = null;    private LazySingletonSync() {        if (lazySingleton!=null){            throw new RuntimeException("单例构造器禁止反射调用");        }    }    //在静态方法上加锁就等于在静态类上加锁    /*public synchronized static LazySingletonSyco getInstance() {        if (lazySingleton == null) {            lazySingleton = new LazySingletonSyco();        }        return lazySingleton;    }*/    public static LazySingletonSync getInstance() {        synchronized (LazySingletonSync.class){            if (lazySingleton == null) {                lazySingleton = new LazySingletonSync();            }        }        return lazySingleton;    }}